package sc.prototype.common;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;

import org.apache.commons.lang.builder.ReflectionToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Utils implements ConsoleUtil {

    static Logger logger = LoggerFactory.getLogger(Utils.class);

    public static void trySleep(long millis) {
        try {
            Thread.sleep(millis);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
    }

    public static void waitInput(String hint) {
        try {
            Console.info(hint);
            int c = System.in.read();
            Console.info("{}", c);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static String toString(Object object) {
        return ReflectionToStringBuilder.toString(object, ToStringStyle.SHORT_PREFIX_STYLE);
    }

    public static void main(String[] args) {
        try {
            String orgStr = "&lt;";
            logger.info(orgStr);
            String rst = URLEncoder.encode(orgStr, "UTF-8");
            logger.info(rst);
            String org = URLDecoder.decode(rst, "UTF-8");
            logger.info(org);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }
}
